﻿using System;
using FunctionalCLR.Core;
using FunctionalCLR.Shell;
using Zove.Runtime;

namespace Zove.Shell.Modelling
{
    public class PopulateNode : FuncNode
    {
        public PopulateNode()
            : base()
        {
            base.Value = "populate";
        }

        public override object Evaluate()
        {
            if (Parameters.Count < 0)
            {
                throw new ArgumentException(
                    "usage: new(modelName)");
            }

            string modelName = Convert.ToString(
                Parameters[0].Evaluate());
            if (string.IsNullOrEmpty(modelName))
            {
                throw new ArgumentException(
                    "usage: populate(modelName)");
            }

            try
            {
                Instance instance = new Instance(modelName);
                return instance;
            }
            catch (Exception ex)
            {

            }

            return null;
        }
    }
}
